#@layout()

#define css()
<link rel="stylesheet" type="text/css" href="/assets/css/tag/jquery.tagsinput.css" />
<link rel="stylesheet" type="text/css" href="/assets/css/tag/jquery-ui.css" />
#end

#define main()
<div class="wrap" id="wrap">
	<div class="container">
		<div class="row">
			<div class="col-xs-12 col-md-12">
				<div class="panel panel-default">
					<div class="panel-heading">
						<i class="fa fa-pencil-square"></i>写文章
					</div>
				
					<div class="panel-body">
						<div id="message"></div>
						<form class="form-horizontal" id="article-detail-form" action="/blog/post" method="post">
							<div class="form-group">
								<label for="id_title" class="col-sm-2 control-label no-padding-right">标题</label>
								<div class="col-sm-8" id="id_title">
									<input type="text" class="form-control" name="articleTitle" maxlength="100" required>
								</div>
							</div>
							<div class="form-group">
								<label for="desc" class="col-sm-2 control-label no-padding-right">内容</label>
								<div class="col-sm-8" id="desc">
									  <div class="content-box">
										  <script id="container_target" name="articleContent"  type="text/plain"></script>
									  </div>
								</div>
							</div>
							<div class="form-group">
								<label for="btags" class="col-sm-2 control-label no-padding-right">标签</label>
								<div class="col-sm-8" id="btags">
									<input id="tags_1" type="text" class="tags" name="tags" />
									<p class="help-block" style="font-size: 12px;">添加相关标签，用逗号或空格分隔 (最多4个，只取前4个标签).</p>
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-2 control-label no-padding-right">分类</label>
								<div class="col-sm-3">
									<select class="form-control" name="articleType">
										#for(type : aTypes)
										<option value="#(type.id)">#(type.article_type)</option>
										#end
									</select>
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-2 control-label no-padding-right">访问权限</label>
								<div class="col-sm-3">
									<select class="form-control" name="privacy">
										<option value="0">公开</option>
										<option value="1">私密</option>
									</select>
								</div>
							</div>
							<div class="row">
								<div class="form-group">
									<div class="text-center">
										<button type="submit" class="btn btn-primary">发布</button>
									</div>
								</div>
							</div>
						</form>
					</div>
				</div>
			</div>
		</div>

	</div>
</div>
#end

#define js()
<script type="text/javascript" src="/assets/js/tag/jquery-1.8.0.min.js"></script> 
<script type="text/javascript" src="/assets/js/tag/jquery.tagsinput.js"></script> 
<script type="text/javascript" src="/assets/js/tag/jquery-ui.min.js"></script>
<script type="text/javascript" src="/assets/jquery_form/jquery.form.min.js"></script>
<script type="text/javascript" src="/assets/layer-v3.0.2/layer/layer.js"></script>
#include("/_view/blog/common/detail_info_editor.html") 
<script type="text/javascript">
//设置上传类型为article
ue.ready(function() {
	ue.execCommand('serverparam', {
		'uploadType': 'article'
	});
});
/*通过java过滤获取纯文本，这里不做出来*/
/*var summary_;
function getText()
{
	summary_ = UE.getEditor('container_target').getContentTxt();
	console.log(summary_);
}*/

$(function() {
	var tagNum = $('.tag').size();
	if (tagNum < 4) {
		$('#tags_1').tagsInput({width:'auto'});
	}
});

$(document).ready(function() {
	$("#article-detail-form").ajaxForm({
		dataType: "json",
		success: function(ret) {
			// 业务层验证成功
			if(ret.isOk) {
				layer.alert(ret.msg, {icon: 6});
				//跳转到文章详情
				location.href = "/view/article/"+ret.postId;
				return ;
			}
			// 业务层验证失败
			else if (ret.isFail) {
				layer.alert(ret.msg);
				return ;
			}
		}
		, error: function(ret) { }              // ret.status != 200 时回调
		, complete: function(ret) { }       // 无论是 success 还是 error，最终都会被回调
	});
});
</script>
#end